<template>
	<view class="content" :style="{'height':contentHeight}">
		<view class="banner">
			<image src="https://images.linglinggong.net/XCX/danwang.png" mode=""></image>
		</view>
		<view class="list" :style="{'padding-bottom':token?'120rpx':''}">
			<view class="fix-tab"> {{rank}}</view>
			<view style="width: 100%;height: 2rpx;">
			</view>
			<view class="time"> 距离本周结束还有 <span>{{remainDay}}</span>天 </view>
			<view class="title">
				<view class="">
					<span>排名</span> <span>用户</span>
				</view>
				<span>单数</span>
			</view>
			<view v-for="(item,index) in weekList.slice(0,100)" :class="[[0,1,2].includes(index)?'leader':'item']">
				<view class="left">
					<view class="list-icon">
						<image class="list-icon1" v-if="index==0"
							src="https://images.linglinggong.net/static/danwang/top1.png" mode=""></image>
						<image class="list-icon2" v-if="index==1"
							src="https://images.linglinggong.net/static/danwang/top2.png" mode=""></image>
						<image class="list-icon3" v-if="index==2"
							src="https://images.linglinggong.net/static/danwang/top3.png" mode=""></image>
					</view>
					<span class="number" v-if="![0,1,2].includes(index)">{{index+1}}</span>
					<view class="user">
						<view class="img">
							<image
								:style="{'width':[0,1].includes(index)?'80rpx':'60rpx','height':[0,1].includes(index)?'80rpx':'60rpx','border-radius':[0,1].includes(index)?'40rpx':''}"
								:src="`https://images.linglinggong.net/${item.avatar}`" mode=""></image>
						</view>
						<span>{{item.userName}}</span>
					</view>
				</view>
				<view class="right">{{item.orderCount}}</view>
			</view>
		</view>
		<view class="fixed-item" v-if="token">
			<view class="left">
				<span v-if="user.userIndex>150||!user.userIndex">100+</span>
				<image v-else-if="[1,2,3].includes(user.userIndex)"
					:src="`https://images.linglinggong.net/static/danwang/top${user.userIndex}.png`" mode=""></image>
				<span v-else>{{user.userIndex}}</span>
				<view class="fix-img">
					<image :src="`https://images.linglinggong.net/${user.avatar}`" mode=""></image>
				</view>
				<span>{{user.userName}}</span>
			</view>
			<view class="right">
				<view>
					{{user.orderCount}}
				</view>
				<view v-if="100<user.userIndex&&user.userIndex<151"> (距离上榜还差 {{user.orderCount}} 单) </view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				weekList: [],
				remainDay: '', //本周剩余天数
				nub: 100,
				user: {},
				userIndex: '',
				rank: '',
				token: false,
				contentHeight: ''
			};
		},
		onShow() {
			this.contentHeight = uni.getWindowInfo().windowHeight + "px"
			if (uni.getStorageSync('token')) {
				this.token = true
			} else {
				this.token = false
			}
			this.getList()
			this.getSetting()
			this.getTime()
		},
		methods: {
			onNavigationBarButtonTap() {
				uni.navigateTo({
					url: '/pages/week-list/rule/rule'
				})
			},
			async getSetting() {
				let res = await this.$fetch(this.$api.property_list_by_type_and_key, {
					type: 1,
					key: 'single_king_weekly_list_config'
				}, 'POST')
				if (res.code != 0) {
					return
				}
				this.rank = res.data
			},
			async getList() {
				let res = await this.$fetch(this.$api.findUserOrderWeekRanking, {}, 'GET')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.weekList = res.data
				for (let i = 0; i < this.weekList.length; i++) {
					if (this.weekList[i].isUser === 1) {
						this.user = this.weekList[i]
					} else {
						if (this.token) {
							this.user.userName = uni.getStorageSync('userInfo').user.userName
							this.user.avatar = uni.getStorageSync('userInfo').user.avatar
						}
					}
				}
			},
			getTime() {
				var nowDay = new Date()
				var weekDay = [7, 1, 2, 3, 4, 5, 6];
				var myDate = new Date(Date.parse(nowDay));
				this.remainDay = 8 - weekDay[myDate.getDay()]
			},
		},
	}
</script>
<style lang="less" scoped>
	.content {
		background: linear-gradient(#FF6600, #F5DDC8, #FFA303);
		overflow-y: scroll;

		.banner {
			width: 100%;
			height: 862rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.list {
			width: 690rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin: 0 auto;
			margin-top: -390rpx;
			position: relative;

			.fix-tab {
				position: absolute;
				top: -50rpx;
				left: 50%;
				margin-left: -209rpx;
				width: 418rpx;
				height: 100rpx;
				padding: 0 40rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 60rpx;
				color: #FFFFFF;
				font-size: 32rpx;
				font-weight: bold;
				background: linear-gradient(#FF8B00, #FF3D00);
				box-shadow: 2rpx 2rpx 6rpx 2rpx #F55F00;
			}

			.time {
				margin-top: 90rpx;
				text-align: center;
				font-size: 32rpx;
				font-weight: bold;
				color: #333333;

				span {
					color: #EB4009;
					font-size: 36rpx;
					padding: 0 10rpx;
				}
			}

			.title {
				width: 654rpx;
				height: 80rpx;
				color: #7F7F7F;
				font-size: 32rpx;
				line-height: 80rpx;
				padding: 0 40rpx;
				box-sizing: border-box;
				background: #F1F1F5;
				margin: 0 auto;
				margin-top: 30rpx;
				margin-bottom: 20rpx;
				border-radius: 10rpx;
				display: flex;
				justify-content: space-between;

				view {
					span {
						margin-right: 60rpx;
					}
				}
			}

			.leader {
				height: 104rpx;
				border-radius: 20rpx;
				box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(119, 165, 233, 0.16);
				box-sizing: border-box;
				padding: 0 40rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 auto;
				margin-bottom: 10rpx;

				.left {
					display: flex;
					justify-content: start;
					align-items: center;

					.list-icon {
						display: flex;
						justify-content: center;
						align-items: center;

						.list-icon1 {
							width: 80rpx;
							height: 84rpx;
							margin-right: 46rpx;
						}

						.list-icon2 {
							width: 78rpx;
							height: 82rpx;
							margin-left: 1rpx;
							margin-right: 46rpx;
						}

						.list-icon3 {
							width: 66rpx;
							height: 70rpx;
							margin-right: 70rpx;
							margin-left: 5rpx;
						}
					}

					.user {
						display: flex;
						align-items: center;

						.img {
							margin-right: 10rpx;

							image {
								width: 100%;
								height: 100%;
								border-radius: 30rpx;
							}
						}
					}
				}

				.right {
					padding-right: 20rpx;
				}
			}

			.item {
				height: 100rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 20rpx;
				margin-bottom: 20rpx;
				padding: 0 20rpx;
				box-sizing: border-box;
				border-bottom: 1px solid #F1F1F5;

				.left {
					display: flex;
					justify-content: start;
					align-items: center;

					.number {
						width: 80rpx;
						height: 100%;
						text-align: center;
						line-height: 100rpx;
						margin-right: 60rpx;
					}

					.user {
						display: flex;
						align-items: center;

						.img {
							width: 60rpx;
							height: 60rpx;
							margin-right: 10rpx;

							image {
								width: 100%;
								height: 100%;
								border-radius: 30rpx;
							}
						}
					}
				}

				.right {
					padding-right: 20rpx;
				}
			}
		}

		.fixed-item {
			width: 100vw;
			height: 140rpx;
			position: fixed;
			bottom: -20rpx;
			padding: 0 90rpx 0 70rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 20rpx;

			.left {
				display: flex;
				justify-content: start;
				align-items: center;

				span:nth-child(1) {
					width: 80rpx;
					text-align: center;
					margin-right: 55rpx;
					font-size: 40rpx;
					font-weight: bold;
				}

				image {
					width: 80rpx;
					height: 84rpx;
					margin-right: 55rpx;
				}

				.fix-img {
					width: 80rpx;
					height: 80rpx;
					margin-right: 20rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 40rpx;
					}
				}
			}

			.right {
				text-align: right;
				font-weight: bold;

				view:nth-child(1) {
					color: #333333;
					font-size: 40rpx;
				}

				view:nth-child(2) {
					font-size: 28rpx;
					color: #FF6A06;
				}
			}
		}
	}
</style>
